package com.xu.commons.until;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



public class PropsUtil {
	  private static final Logger logger = LoggerFactory.getLogger(PropsUtil.class);
	  
	  public static Properties loadProps(String propsPath){
		  Properties properties =new Properties();
		  InputStream is  =null;
		  try {
		 
		  if (StringUtil.isEmpty(propsPath)) {
              throw new IllegalArgumentException();
          }
		  String str=".properties";
		  if(propsPath.lastIndexOf(str)==-1){
			  propsPath+=str;
		  }
		  is = Thread.currentThread().getContextClassLoader().getResourceAsStream(propsPath);
		  
			properties.load(is);
		} catch (IOException e) {
			   logger.error("加载属性文件出错！", e);
			// TODO Auto-generated catch block
	
			throw new RuntimeException(e);
		}finally{
			
				try {
					if(is!=null){
					is.close();
					}
				} catch (IOException e) {
					  logger.error("释放资源出错！", e);
					e.printStackTrace();
				}
			
		}
		  return properties;
		  
	  }
}
